package com.easylinkin.linkappapi.constructionalbum.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easylinkin.linkappapi.common.exceptions.BusinessException;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.common.model.SortModel;
import com.easylinkin.linkappapi.common.service.CommonService;
import com.easylinkin.linkappapi.common.service.OSSService;
import com.easylinkin.linkappapi.common.utils.StringUtil;
import com.easylinkin.linkappapi.common.utils.excel.ExcelConstant;
import com.easylinkin.linkappapi.common.utils.excel.ExcelTools;
import com.easylinkin.linkappapi.common.utils.file.FileExt;
import com.easylinkin.linkappapi.common.utils.file.ZipFileUtil;
import com.easylinkin.linkappapi.common.utils.io.OutputStreamUtil;
import com.easylinkin.linkappapi.constructionalbum.dto.ConstructionAlbumDto;
import com.easylinkin.linkappapi.constructionalbum.entity.ConstructionAlbum;
import com.easylinkin.linkappapi.constructionalbum.entity.vo.ConstructionAlbumDtoInfoVo;
import com.easylinkin.linkappapi.constructionalbum.entity.vo.ConstructionAlbumInfoVo;
import com.easylinkin.linkappapi.constructionalbum.entity.vo.ConstructionAlbumVo;
import com.easylinkin.linkappapi.constructionalbum.mapper.ConstructionAlbumMapper;
import com.easylinkin.linkappapi.constructionalbum.service.ConstructionAlbumService;
import com.easylinkin.linkappapi.facerecognition.service.oss.ObjectStorageInternalService;
import com.easylinkin.linkappapi.photoalbum.util.ExportUtil;
import com.easylinkin.linkappapi.security.context.LinkappUserContextProducer;
import com.easylinkin.linkappapi.security.entity.LinkappUser;
import com.easylinkin.linkappapi.tenant.entity.LinkappTenant;
import com.easylinkin.linkappapi.tenant.mapper.LinkappTenantMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * ConstructionAlbum表服务实现类
 *
 * @author zhengwen
 * @date 2022/11/07
 */
@Slf4j
@Service("appConstructionAlbumService")
public class ConstructionAlbumServiceImpl extends ServiceImpl
        <ConstructionAlbumMapper, ConstructionAlbum> implements ConstructionAlbumService {
    @Resource
    private CommonService commonService;
    @Resource
    private LinkappUserContextProducer linkappUserContextProducer;

    @Resource
    private LinkappTenantMapper linkappTenantMapper;


    @Autowired
    @Qualifier("ossInternal")
    private ObjectStorageInternalService ossClient;

    @Autowired
    private OSSService ossService;

    @Value("${oss.dir}")
    private String dir;

    @Value("${oss.bucket}")
    private String bucket;

    @Value("${oss.readHost}")
    private String readHost;


    @Override
    public boolean saveOne(ConstructionAlbum appConstructionAlbum) {
        commonService.setCreateAndModifyInfo(appConstructionAlbum);
        // appConstructionAlbum.setTenantId(linkappUserContextProducer.getNotNullCurrent().getTenantId());
        validParamRequired(appConstructionAlbum);
        validRepeat(appConstructionAlbum);
        validParamFormat(appConstructionAlbum);
        return save(appConstructionAlbum);
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateOne(ConstructionAlbum appConstructionAlbum) {
        Assert.notNull(appConstructionAlbum.getId(), "id不能为空");
        commonService.setModifyInfo(appConstructionAlbum);
        //appConstructionAlbum.setTenantId(linkappUserContextProducer.getNotNullCurrent().getTenantId());
        validRepeat(appConstructionAlbum);
        validParamFormat(appConstructionAlbum);
        return updateById(appConstructionAlbum);
    }

    @Override
    public IPage<ConstructionAlbum> selectPage(Page page, ConstructionAlbum appConstructionAlbum) {
        //appConstructionAlbum.setTenantId(linkappUserContextProducer.getNotNullCurrent().getTenantId());
        return baseMapper.selectPage(page, appConstructionAlbum);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByIds(List<Long> idList) {
        return removeByIds(idList);
    }

    @Override
    public void export(ConstructionAlbum appConstructionAlbum, HttpServletRequest request, HttpServletResponse
            response) {

        IPage<ConstructionAlbum> page = selectPage(new Page(0, -1), appConstructionAlbum);
        List<ConstructionAlbum> records = page.getRecords();
        List
                <ConstructionAlbumVo> appConstructionAlbumVos = new ArrayList<>();
        for (ConstructionAlbum expert : records) {
            appConstructionAlbumVos.add(new ConstructionAlbumVo(expert));
        }

        String keyValue = "名称:name,租户id:tenantId";
        String title = "ConstructionAlbum导出数据";
        String fileName = title + ".xls";
        try {
            OutputStream outputStream = OutputStreamUtil
                    .getOutputStream(request, response, fileName);
            ExcelTools.exportExcel(outputStream, keyValue, appConstructionAlbumVos, ExcelConstant.XLS, title);
            response.flushBuffer();
            outputStream.close();
        } catch (IOException e) {
            log.error("excel导出失败", e);
            throw new RuntimeException("excel导出失败！IOException异常" + e.getMessage());
        } catch (Exception e) {
            log.error("excel导出失败", e);
            throw new RuntimeException("excel导出失败！" + e.getMessage());
        }
    }

    @Override
    public RestMessage add(ConstructionAlbumVo constructionAlbumVo) {
        LinkappUser linkappUser = linkappUserContextProducer.getNotNullCurrent();
        String tenantId = linkappUser.getTenantId();
        //参数校验
        Integer dataType = constructionAlbumVo.getDataType();
        cn.hutool.core.lang.Assert.isTrue(dataType != null, "新建类型为空");

        ConstructionAlbum info = null;
        switch (dataType) {
            case 1:
                info = saveAlbum(constructionAlbumVo, linkappUser);
                break;
            case 2:
                info = saveEvent(constructionAlbumVo, linkappUser);
                break;
            case 3:
                info = saveImg(constructionAlbumVo, linkappUser);
                break;
            default:
                break;
        }

        info.setTenantId(tenantId);
        info.setDeleteState(1);
        info.setCreator(linkappUser.getId().toString());
        info.setCreateTime(DateUtil.date());
        info.setModifier(info.getCreator());
        info.setModifyTime(info.getCreateTime());

        //执行保存
        int num = baseMapper.insert(info);
        if (num != 1) {
            return RestBuilders.failureMessage().setMessage("新增失败");
        }

        return RestBuilders.successBuilder().build();
    }

    /**
     * 保存照片
     *
     * @param constructionAlbumVo 照片vo
     * @param linkappUser         租户
     * @return 照片信息
     */
    private ConstructionAlbum saveImg(ConstructionAlbumVo constructionAlbumVo, LinkappUser linkappUser) {
        cn.hutool.core.lang.Assert.isTrue(StringUtils.isNotBlank(constructionAlbumVo.getName()), "照片名称不能为空");
        cn.hutool.core.lang.Assert.isTrue(StringUtils.isNotBlank(constructionAlbumVo.getSourceUrl()), "照片url不能为空");
        //查询父级
        ConstructionAlbum parentInfo = baseMapper.selectById(constructionAlbumVo.getParentId());
        cn.hutool.core.lang.Assert.isTrue(parentInfo != null || parentInfo.getDeleteState() == 1, "事件不存在");
        String parentIds = parentInfo.getParentIds() + parentInfo.getId() + ",";

        ConstructionAlbum info = new ConstructionAlbum();
        BeanUtil.copyProperties(constructionAlbumVo, info, CopyOptions.create().setIgnoreNullValue(true));
        info.setParentIds(parentIds);

        return info;
    }

    /**
     * 保存事件
     *
     * @param constructionAlbumVo 事件vo
     * @param linkappUser         租户
     * @return 事件信息
     */
    private ConstructionAlbum saveEvent(ConstructionAlbumVo constructionAlbumVo, LinkappUser linkappUser) {
        cn.hutool.core.lang.Assert.isTrue(StringUtils.isNotBlank(constructionAlbumVo.getName()), "事件名称不能为空");
        //查询，验证重复
        String tenantId = linkappUser.getTenantId();
        QueryWrapper<ConstructionAlbum> qw = new QueryWrapper<>();
        qw.eq("tenant_id", tenantId);
        qw.eq("delete_state", 1);
        qw.eq("name", constructionAlbumVo.getName());
        qw.eq("data_type", constructionAlbumVo.getDataType());

        String parentIds = ",0,";
        qw.eq("parent_id", constructionAlbumVo.getParentId());
        int count = baseMapper.selectCount(qw);
        cn.hutool.core.lang.Assert.isTrue(count == 0, "名称重复");

        //查询父级
        ConstructionAlbum parentInfo = baseMapper.selectById(constructionAlbumVo.getParentId());
        cn.hutool.core.lang.Assert.isTrue(parentInfo != null, "相册不存在");
        parentIds = parentInfo.getParentIds() + parentInfo.getId() + ",";
        qw.eq("parent_id", constructionAlbumVo.getParentId());

        //补充数据
        ConstructionAlbum info = new ConstructionAlbum();
        BeanUtil.copyProperties(constructionAlbumVo, info, CopyOptions.create().setIgnoreNullValue(true));
        info.setParentIds(parentIds);

        return info;
    }

    /**
     * 保存相册
     *
     * @param constructionAlbumVo 相册vo
     * @param linkappUser         租户
     * @return 相册信息
     */
    private ConstructionAlbum saveAlbum(ConstructionAlbumVo constructionAlbumVo, LinkappUser linkappUser) {
        cn.hutool.core.lang.Assert.isTrue(StringUtils.isNotBlank(constructionAlbumVo.getName()), "相册名称不能为空");
        //查询，验证重复
        String tenantId = linkappUser.getTenantId();
        QueryWrapper<ConstructionAlbum> qw = new QueryWrapper<>();
        qw.eq("tenant_id", tenantId);
        qw.eq("delete_state", 1);
        qw.eq("name", constructionAlbumVo.getName());
        qw.eq("data_type", constructionAlbumVo.getDataType());

        String parentIds = ",0,";
        qw.eq("parent_id", constructionAlbumVo.getParentId());
        int count = baseMapper.selectCount(qw);
        cn.hutool.core.lang.Assert.isTrue(count == 0, "名称重复");

        //补充数据
        ConstructionAlbum info = new ConstructionAlbum();
        BeanUtil.copyProperties(constructionAlbumVo, info, CopyOptions.create().setIgnoreNullValue(true));
        info.setParentIds(parentIds);

        return info;
    }

    @Override
    public RestMessage update(ConstructionAlbumVo constructionAlbumVo) {
        LinkappUser linkappUser = linkappUserContextProducer.getNotNullCurrent();
        String tenantId = linkappUser.getTenantId();
        //参数校验
        Long id = constructionAlbumVo.getId();
        cn.hutool.core.lang.Assert.isTrue(id != null, "ID为空");
        //查询原数据
        ConstructionAlbum dbInfo = baseMapper.selectById(id);
        cn.hutool.core.lang.Assert.isTrue(dbInfo != null, "数据不存在");
        constructionAlbumVo.setParentId(dbInfo.getParentId());
        constructionAlbumVo.setDataType(dbInfo.getDataType());

        Integer dataType = constructionAlbumVo.getDataType();
        cn.hutool.core.lang.Assert.isTrue(dataType != null, "变更类型为空");
        switch (dataType) {
            case 1:
                cn.hutool.core.lang.Assert.isTrue(StringUtils.isNotBlank(constructionAlbumVo.getName()), "相册名称不能为空");
                break;
            case 2:
                cn.hutool.core.lang.Assert.isTrue(StringUtils.isNotBlank(constructionAlbumVo.getName()), "事件名称不能为空");
                break;
            case 3:
                cn.hutool.core.lang.Assert.isTrue(StringUtils.isNotBlank(constructionAlbumVo.getName()), "照片名称不能为空");
                break;
            default:
                break;
        }

        //查询，验证重复
        QueryWrapper<ConstructionAlbum> qw = new QueryWrapper<>();
        qw.eq("tenant_id", tenantId);
        qw.ne("id", id);
        qw.eq("delete_state", 1);
        qw.eq("name", constructionAlbumVo.getName());
        qw.eq("data_type", constructionAlbumVo.getDataType());

        String parentIds = ",0,";
        if (constructionAlbumVo.getParentId() == null || constructionAlbumVo.getParentId().intValue() == 0) {
            //查询父级
            qw.eq("parent_id", constructionAlbumVo.getParentId());
        } else {
            //查询父级
            ConstructionAlbum parentInfo = baseMapper.selectById(constructionAlbumVo.getParentId());
            cn.hutool.core.lang.Assert.isTrue(parentInfo != null, "相册不存在");
            parentIds = parentInfo.getParentIds() + parentInfo.getId() + ",";
            qw.eq("parent_id", constructionAlbumVo.getParentId());
        }
        int count = baseMapper.selectCount(qw);
        cn.hutool.core.lang.Assert.isTrue(count == 0, "名称重复");

        constructionAlbumVo.setParentIds(parentIds);

        //补充数据
        BeanUtil.copyProperties(constructionAlbumVo, dbInfo, CopyOptions.create().setIgnoreNullValue(true));

        dbInfo.setTenantId(tenantId);
        dbInfo.setModifier(linkappUser.getId().toString());
        dbInfo.setModifyTime(DateUtil.date());

        //执行保存
        int num = baseMapper.updateById(dbInfo);
        if (num != 1) {
            return RestBuilders.failureMessage().setMessage("修改失败");
        }

        return RestBuilders.successBuilder().build();
    }

    @Override
    public RestMessage getDtoPage(RequestModel<ConstructionAlbumVo> requestModel) {
        ConstructionAlbumVo vo = requestModel.getCustomQueryParams();
        Assert.notNull(vo, "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        List<SortModel> sorts = requestModel.getSorts();
        if (sorts != null) {
            for (SortModel sortModel : sorts) {
                if (sortModel.getField() != null) {
                    sortModel.setField(StringUtil.camel2Underline(sortModel.getField()));
                }
            }
        }
        LinkappUser linkappUser = linkappUserContextProducer.getNotNullCurrent();
        String tenantId = linkappUser.getTenantId();
        vo.setTenantId(tenantId);
        IPage<ConstructionAlbumDto> record = baseMapper.selectDtoPage(requestModel.getPage(), vo, sorts);

        return RestBuilders.successBuilder(record).build();
    }

    @Override
    public RestMessage batchDelete(List<Long> idList) {
        LinkappUser linkappUser = linkappUserContextProducer.getNotNullCurrent();
        String tenantId = linkappUser.getTenantId();

        cn.hutool.core.lang.Assert.isTrue(CollectionUtils.isNotEmpty(idList), "未选择数据");

        Date now = DateUtil.date();
        idList.stream().forEach(d -> {
            //查询
            ConstructionAlbum info = baseMapper.selectById(d);
            if (info != null) {
                UpdateWrapper<ConstructionAlbum> infoDel = new UpdateWrapper<>();
                infoDel.eq("id", info.getId());
                infoDel.set("delete_state", 0);
                infoDel.set("modifier", linkappUser.getId());
                infoDel.set("modify_time", now);
                baseMapper.update(null, infoDel);

                String parentIds = info.getParentIds();
                UpdateWrapper<ConstructionAlbum> delQw = new UpdateWrapper<>();
                delQw.eq("tenant_id", tenantId);
                delQw.likeRight("parent_ids", parentIds + info.getId() + ",");
                delQw.set("delete_state", 0);
                delQw.set("modifier", linkappUser.getId());
                delQw.set("modify_time", now);
                baseMapper.update(null, delQw);
            }
        });

        return RestBuilders.successBuilder().build();
    }

    @Override
    public RestMessage saveEventImgs(ConstructionAlbumInfoVo constructionAlbumInfoVoVo) {
        LinkappUser linkappUser = linkappUserContextProducer.getNotNullCurrent();
        String tenantId = linkappUser.getTenantId();

        //相册信息
        ConstructionAlbum albumInfo = constructionAlbumInfoVoVo.getAlbumInfo();
        cn.hutool.core.lang.Assert.isTrue(albumInfo != null, "未选择相册");
        cn.hutool.core.lang.Assert.isTrue(albumInfo.getId() != null, "选择相册ID为空");
        //事件信息
        ConstructionAlbum eventInfo = constructionAlbumInfoVoVo.getEventInfo();
        cn.hutool.core.lang.Assert.isTrue(eventInfo != null, "未选择事件");

        List<ConstructionAlbum> imgList = constructionAlbumInfoVoVo.getImgList();
        cn.hutool.core.lang.Assert.isTrue(CollectionUtil.isNotEmpty(imgList), "上传事件照片为空");

        //查询相册信息
        ConstructionAlbum dbAlbumInfo = baseMapper.selectById(albumInfo.getId());
        cn.hutool.core.lang.Assert.isTrue(dbAlbumInfo != null || dbAlbumInfo.getDeleteState() == 0, "选择的相册不存在");

        //事件有id表示原事件
        if (eventInfo.getId() == null) {
            //校验相册下时间是否重复
            ConstructionAlbumVo constructionAlbumVo = new ConstructionAlbumVo();
            constructionAlbumVo.setDataType(2);
            constructionAlbumVo.setParentId(albumInfo.getId());
            constructionAlbumVo.setName(eventInfo.getName());
            ConstructionAlbum info = saveEvent(constructionAlbumVo, linkappUser);
            info.setTenantId(tenantId);
            info.setDeleteState(1);
            info.setCreator(linkappUser.getId().toString());
            info.setCreateTime(DateUtil.date());
            info.setModifier(info.getCreator());
            info.setModifyTime(info.getCreateTime());
            baseMapper.insert(info);
            eventInfo = info;
        } else {
            //查询事件
            ConstructionAlbum dbEventInfo = baseMapper.selectById(eventInfo.getId());
            cn.hutool.core.lang.Assert.isTrue(dbEventInfo != null || dbEventInfo.getDeleteState() == 1, "选择的事件不存在");
            eventInfo = dbEventInfo;
        }

        //保存照片信息
        Date now = DateUtil.date();
        ConstructionAlbum finalEventInfo = eventInfo;
        imgList.stream().forEach(m -> {
            ConstructionAlbumVo vo = new ConstructionAlbumVo();
            BeanUtil.copyProperties(m, vo, CopyOptions.create().setIgnoreNullValue(true));
            vo.setParentId(finalEventInfo.getId());

            ConstructionAlbum info = saveImg(vo, linkappUser);

            info.setDataType(3);
            info.setParentIds(finalEventInfo.getParentIds() + finalEventInfo.getId() + ",");
            info.setTenantId(tenantId);
            info.setDeleteState(1);
            info.setCreator(linkappUser.getId().toString());
            info.setCreateTime(now);
            info.setModifier(info.getCreator());
            info.setModifyTime(info.getCreateTime());

            //执行保存
            baseMapper.insert(info);
        });


        return RestBuilders.successBuilder().build();
    }

    @Override
    public RestMessage eventDetail(Long id) {
        ConstructionAlbumDtoInfoVo dtoInfoVo = new ConstructionAlbumDtoInfoVo();
        //查询当前信息
        ConstructionAlbumDto eventInfo = baseMapper.selectDtoById(id);
        cn.hutool.core.lang.Assert.isTrue(eventInfo != null, "事件不存在");
        dtoInfoVo.setEventDtoInfo(eventInfo);

        Long parentId = eventInfo.getParentId();
        ConstructionAlbumDto parentInfo = baseMapper.selectDtoById(parentId);
        dtoInfoVo.setAlbumDtoInfo(parentInfo);

        //项目信息
        LinkappTenant tenant = linkappTenantMapper.getById(eventInfo.getTenantId());
        dtoInfoVo.setLinkappTenant(tenant);

        //查询子集
        List<ConstructionAlbumDto> children = baseMapper.selectChildDtoList(id);
        dtoInfoVo.setImgList(children);

        return RestBuilders.successBuilder().data(dtoInfoVo).build();
    }

    @Override
    public String exportAppAlbum(ConstructionAlbumInfoVo constructionAlbumInfoVo) {
        String fileName = null;
        String albumName = null;
        List<FileExt> fileExtList = new ArrayList<>();
        Integer dataType = constructionAlbumInfoVo.getDataType();
        switch (dataType) {
            case 1:
                break;
            case 2:
                albumName = exportEventImgs(constructionAlbumInfoVo, fileExtList);
                break;
            case 3:
                break;
            default:
                break;
        }


        //开始导出
        InputStream fileInputStream = null;
        try {
            String today = DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_MS_FORMAT);
            fileInputStream = ZipFileUtil.getFileInputStream(today, fileExtList);
            //上传文件到oss
            String resultFilename =
                    albumName + "_" + today + ".zip";
            ossClient.putObject(bucket, resultFilename, fileInputStream, "application/octet-stream");
            fileName = ossService.generateUrl(resultFilename);
        } catch (Exception e) {
            log.error("打包失败：", e);
            throw new BusinessException("下载文件打包失败");
        } finally {
            // 关闭流
            try {
                if (null != fileInputStream) {
                    fileInputStream.close();
                }
            } catch (IOException e) {
                log.error("打包失败：", e);
            }
        }
        return fileName;
    }

    /**
     * 导出事件照片
     *
     * @param constructionAlbumInfoVo 入参vo
     * @param fileExtList             文件list
     * @return 相册名称
     */
    private String exportEventImgs(ConstructionAlbumInfoVo constructionAlbumInfoVo, List<FileExt> fileExtList) {
        String ids = constructionAlbumInfoVo.getIds();
        List<String> idList = Stream.of(ids.split(",")).collect(Collectors.toList());
        AtomicReference<Long> albumId = new AtomicReference<>();
        idList.stream().forEach(d -> {
            //查询事件信息
            Long eventId = Long.parseLong(d);
            ConstructionAlbum event = baseMapper.selectById(eventId);
            //查询相册信息
            albumId.set(event.getParentId());


            //查询照片信息
            QueryWrapper<ConstructionAlbum> qw = new QueryWrapper<>();
            qw.eq("parent_id", eventId);
            qw.eq("data_type", 3);
            qw.eq("delete_state", 1);
            List<ConstructionAlbum> imgList = baseMapper.selectList(qw);
            if (CollectionUtil.isNotEmpty(imgList)) {

                AtomicInteger count = new AtomicInteger(1);
                imgList.stream().forEach(a -> {
                    String url = a.getSourceUrl();
                    if (StringUtils.isNotEmpty(url)) {
                        url = url.replace("+", "%2B");
                        url = url.replace("&", "%26");
                        FileExt fileInfoByUrl = ExportUtil
                                //.getFileInfoByUrl(url,prefix, com.easylinkin.linkappapi.common.utils.DateUtil.getyyyyMMddHHmmssSSSNumberString(event.getCreateTime()),a.getName(), count.get());
                                .getFileInfoByUrl(url, event.getName(), DateUtil.format(event.getCreateTime(), DatePattern.PURE_DATETIME_MS_FORMAT), a.getName(), (long) count.get());
                        if (null != fileInfoByUrl && null != fileInfoByUrl.getInputStream()) {
                            fileInfoByUrl.setFileName(a.getName());
                            fileInfoByUrl.setFolder(event.getName());
                            fileExtList.add(fileInfoByUrl);
                            count.getAndIncrement();
                        } else {
                            log.error("打包失败：名称【{}】", url);
                        }
                    }
                });
            }
        });

        ConstructionAlbum album = baseMapper.selectById(albumId.get());
        return album.getName();
    }


    @Override
    public ConstructionAlbum getOneById(Serializable id) {
        return baseMapper.getOneById(id);
    }

    /**
     * 校验重复
     */
    private void validRepeat(ConstructionAlbum appConstructionAlbum) {
        /* QueryWrapper<ConstructionAlbum> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", appConstructionAlbum.getName());
        queryWrapper.eq("tenant_id", linkappUserContextProducer.getNotNullCurrent().getTenantId());
        List<ConstructionAlbum> list = baseMapper.selectList(queryWrapper);
        if (list.size() == 0) {
            return;
        }
        if (list.size() > 1) {
            throw new BusinessException("名称有重复");
        }
        if (ObjectUtils.isEmpty(appConstructionAlbum.getId())) {
            throw new BusinessException("名称已存在");
        }
        if (!appConstructionAlbum.getId().equals(list.get(0).getId())) {
            throw new BusinessException("名称已存在");
        }
                    */

    }


    /**
     * 校验参数必填
     */
    private void validParamRequired(ConstructionAlbum appConstructionAlbum) {
        //Assert.notNull(appConstructionAlbum, "参数为空");
        //Assert.isTrue(StringUtils.isNotBlank(appConstructionAlbum.getName()), "名称为空");
    }

    /**
     * 校验参数格式
     */
    private void validParamFormat(ConstructionAlbum appConstructionAlbum) {
        //Assert.isTrue(appConstructionAlbum.getName() == null || appConstructionAlbum.getName().length() <= 50,
        //        "名称超长");
    }
}

